perm filename APPROX.LSP[QLA,LSP] blob sn#768583 filedate 1984-08-27 generic text, type C, neo UTF8
COMMENT āŠ—   VALID 00002 PAGES
C REC  PAGE   DESCRIPTION
C00001 00001
C00002 00002	 Monte Carlo Approximation to π
C00003 ENDMK
CāŠ—;
;;; Monte Carlo Approximation to π

(declare (special random))

(setq random 21.)
(defun rand ()
       (setq random (remainder (* random 17.) 251.)))

(defun approx-pi (trials)
 (setq random 21.)
 (do ((tr trials (1- tr))
      (passed 0))
     ((zerop tr)
      (sqrt (//$ 6.0 (//$ (float passed)(float trials)))))
     (cond ((= (gcd (rand)(rand)) 1)
	    (setq passed (1+ passed))))))